package com.developer.fans;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class SkyConstants {
    public static float mDiv = 1;
    public static float mDpi = 1;

    static int mWidth, mHeight;

    public static void init(Context context) {
        mWidth = SkyConstants.getDisplayWidth(context);
        mHeight = SkyConstants.getDisplayHeight(context);

        float div = (float) mWidth / (float) 1920;
        initResolution(context, div, div / SkyConstants.getDisplayDensity(context));
    }

    public static void initResolution(Context context, float div, float dpi) {
        mDiv = div;
        mDpi = dpi;
    }

    public static int Div(int x) {
        return (int) (x * mDiv);
    }

    public static int Dpi(int x) {
        return (int) (x * mDpi);
    }

    public static float getDisplayDensity(Context context) {
        Context thisContext = context;
        DisplayMetrics dm = new DisplayMetrics();
        dm = thisContext.getApplicationContext().getResources().getDisplayMetrics();
        float density = dm.density;
        return density;
    }

    public static int getDisplayWidth(Context context) {
        Context thisContext = context;
        Display display = ((WindowManager) thisContext.getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        DisplayMetrics dm = new DisplayMetrics();
        display.getMetrics(dm);
        return dm.widthPixels;
    }

    public static int getDisplayHeight(Context context) {
        Context thisContext = context;
        Display display = ((WindowManager) thisContext.getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        DisplayMetrics dm = new DisplayMetrics();
        display.getMetrics(dm);
        int screenHeight = dm.heightPixels;
        return screenHeight;
    }

}
